Skip to main content

libobs_simple\sources\linux\sources/
xcomposite_input.rs

1use libobs_wrapper::{
2    data::ObsObjectBuilder,
3    sources::{ObsSourceBuilder, ObsSourceRef},
4};
5
6use crate::sources::macro_helper::{define_object_manager, impl_custom_source};
7
8define_object_manager!(
9    #[derive(Debug)]
10    /// A source to capture X11 windows using XComposite.
11    ///
12    /// This source provides window capture functionality on Linux systems running X11
13    /// using the XComposite extension. It can capture individual windows with their
14    /// transparency and effects intact.
15    struct XCompositeInputSource("xcomposite_input", *mut libobs::obs_source) for ObsSourceRef {
16        /// Window to capture (window ID as string)
17        #[obs_property(type_t = "string")]
18        capture_window: String,
19
20        /// Crop from top (in pixels)
21        #[obs_property(type_t = "int")]
22        cut_top: i64,
23
24        /// Crop from left (in pixels)
25        #[obs_property(type_t = "int")]
26        cut_left: i64,
27
28        /// Crop from right (in pixels)
29        #[obs_property(type_t = "int")]
30        cut_right: i64,
31
32        /// Crop from bottom (in pixels)
33        #[obs_property(type_t = "int")]
34        cut_bot: i64,
35
36        /// Whether to show the cursor in the capture
37        #[obs_property(type_t = "bool")]
38        show_cursor: bool,
39
40        /// Include window border/decorations
41        #[obs_property(type_t = "bool")]
42        include_border: bool,
43
44        /// Exclude alpha channel (disable transparency)
45        #[obs_property(type_t = "bool")]
46        exclude_alpha: bool,
47    }
48);
49
50impl_custom_source!(XCompositeInputSource, [
51    //TODO Add support for the `linux-capture` type as it does not contain the `title` field (its 'name' instead)
52    "hooked": {struct HookedSignal {
53        name: String,
54        class: String;
55        POINTERS {
56            source: *mut libobs::obs_source_t,
57        }
58    }},
59    //TODO Add support for the `linux-capture` type as it does not contain the `title` field (its 'name' instead)
60    "unhooked": {struct UnhookedSignal {
61        POINTERS {
62            source: *mut libobs::obs_source_t,
63        }
64    }},
65]);
66
67impl ObsSourceBuilder for XCompositeInputSourceBuilder {
68    type T = XCompositeInputSource;
69
70    fn build(self) -> Result<Self::T, libobs_wrapper::utils::ObsError>
71    where
72        Self: Sized,
73    {
74        let runtime = self.runtime.clone();
75        let info = self.object_build()?;
76        let source = ObsSourceRef::new_from_info(info, runtime)?;
77
78        XCompositeInputSource::new(source)
79    }
80}